﻿<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<%!
/**
 * 获取科室预约信息 对应的存储过程名称 -》获取科室预约信息
 * @param ksdm 科室代码
 * @param kssj 开始时间
 * @param jssj 结束时间
 */
	public List getPlainAppoint(Map<String, String> param) {
		Connection connection = null;
		CallableStatement statement = null;
		List<Map<String, String>> retList = new ArrayList<Map<String, String>>();
		try {
			connection = getConn();
			statement = connection.prepareCall("{? = call 获取科室预约信息(?,?,?)}"); 
			statement.registerOutParameter(1, Types.INTEGER);
			statement.setString(2, param.get("ksdm"));
			statement.setString(3, Tools.getDesc(param.get("kssj"), ""));
			statement.setString(4, Tools.getDesc(param.get("jssj"), ""));
			ResultSet rs = statement.executeQuery();
			Map<String, String> map = null;
			while(rs.next()){
				map = new HashMap<String, String>();
				// map.put("ShowLable", rs.getString("ShowLable"));
				map.put("allhx", rs.getString("allhx"));
				map.put("syhx", rs.getString("syhx"));
				map.put("sjd", rs.getString("sjd"));
				
				//根据时间段判断上下午
				//’07:45-11:30’,’13:00-16:30’,’00:00-23:59
				String sjd =  rs.getString("sjd");
				String [] arr = sjd.split("-");
				String half="";
				if(arr[1].compareTo("12:00")>0 && arr[0].compareTo("12:00")<0) {
					half="0";
				} 
				
				if(arr[1].compareTo("12:00")<0) {
					half="1";
				}
				
				if(arr[0].compareTo("12:00")>0) {
					half="2";
				}
				map.put("half",half);
				map.put("zxrq", rs.getString("zxrq"));
				map.put("pbmxid", rs.getString("pbmxid"));
				retList.add(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
					if (statement != null)
						statement.close(); 
					// if (connection != null)
						// connection.close(); 
				} catch (Exception e) {
					e.printStackTrace();
				}
			return retList;
		}
	}
	
	/**
 * 获取排班医生信息 对应的存储过程名称 -》获取排班医生信息
 * @param ksdm 科室代码
 * @param kssj 开始时间
 * @param jssj 结束时间
 */
	public List getDoctorOnDuty(Map<String, String> param) {
		Connection connection = null;
		CallableStatement statement = null;
		List<Map<String, String>> retList = new ArrayList<Map<String, String>>();
		try {
			connection = getConn();
			statement = connection.prepareCall("{? = call 获取排班医生信息(?,?,?)}"); 
			statement.registerOutParameter(1, Types.INTEGER);

			statement.setString(2, Tools.getDesc(param.get("kssj"), ""));
			statement.setString(3, Tools.getDesc(param.get("jssj"), ""));
			statement.setString(4, param.get("ksdm"));
			ResultSet rs = statement.executeQuery();
			Map<String, String> map = null;
			while(rs.next()){
				map = new HashMap<String, String>();
				map.put("namezc", rs.getString("namezc"));
				map.put("pbkm", rs.getString("pbkm"));
				map.put("pbkmlx", rs.getString("pbkmlx"));
				// map.put("zc_id", rs.getString("zc_id"));
				map.put("name", rs.getString("name"));
				retList.add(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
					if (statement != null)
						statement.close(); 
					// if (connection != null)
						// connection.close(); 
				} catch (Exception e) {
					e.printStackTrace();
				}
			return retList;
		}
	}
%>

<%
	Message msg = new Message();
	try {
		String ksdm =  input.getDesc("ksdm","");//科室代码
		String kssj =  input.getDesc("kssj","20180531");//开始时间
		String jssj =  input.getDesc("jssj","20180630");//结束时间
		
		//获取科室预约信息
		Map<String, String> param  = new HashMap<String,String>(4);
		param.put("ksdm",ksdm);
		param.put("kssj",kssj);
		param.put("jssj",jssj);
		List appointList = getPlainAppoint(param);
		List dutyList = getDoctorOnDuty(param);
		Map ret = new HashMap(2);
		if((appointList == null || appointList.size() == 0) && (dutyList == null || dutyList.size() == 0)) {
			msg.put("errcode",30041);
			msg.put("errmsg","暂无数据");
		} else {
			msg.put("errcode",0);
			ret.put("appointList",appointList);
			ret.put("dutyList",dutyList);
		}
		msg.put("data",ret);
    }catch (Exception e){
	   	msg.put("errcode",FAILURE);
    }
		out.println(msg);
%>